<?php

require_once('pub_inc.php');		//公共包含

$hy_58 = 'http://hy.58.com/job/';
for ($i = 1; $i <= 25; $i++) {
	$html_h = file_get_contents($hy_58.'pn'.$i.'/');
	if (preg_match_all('/<a href=\'([^\']*)\' target="_blank" class="fl" title="([^"]*)">/', $html_h, $m)) {
		foreach ($m[0] as $a) {
			if (preg_match('/<a href=\'([^\']*)\' target="_blank" class="fl" title="([^"]*)">/', $a, $m)) {
				do_pick_content($m[1], $m[2]);
			}
		}
	} 
}
return true;

function do_pick_content($c_url, $c_name) {
	$forum_id = 14;
	$topic = dt_query_one("SELECT id, c_at FROM forum_topic WHERE title LIKE '%$c_name%' AND forum_id = '$forum_id' ORDER BY c_at DESC LIMIT 1");

	//是否刷频
	if (check_topic_live($topic)) return true; 

	$html_c = file_get_contents($c_url);

	//提取内容
	if (preg_match('/<img src="[^"]*">/', $html_c, $m)) {
		$tel = $m[0];
	} else return false;

	if (preg_match('/<table class="jobList">.*/', $html_c, $m)) {
		$job = preg_replace('/href="[^"]*"/', '', $m[0]);
	}

	if (preg_match('/<td class="adress"[^>]*>[^<]*<[^>]*>([^<]*)<\/[^>]*>/', $html_c, $m)) {
		$adr = $m[1];
	}

	//标题
	$title = '【'.$c_name.'】';
	preg_match_all('/<a target="_blank"[^>]*>([^<]*)<\/a>/', $html_c, $m);
	foreach ($m[1] as $t) {
		$title = $title.$t.'、';
	}
	$content = $job.'<hr>'.$tel.'<hr>'.$adr.'<br><br>';

	if ($topic) {
		dt_query("UPDATE forum_topic SET title = '".get_substr(filter_var($title, FILTER_SANITIZE_STRING), 40)."', content = '$content', c_at = '".time()."' WHERE id = ".$topic['id']);
	} else {
		if (!do_topic_add($forum_id, $title, $content)) return false;
	}

	return true;
}
